package org.pucc.data

import java.sql.{Connection, DriverManager}

import org.pucc.common.DatabaseConstant
import org.pucc.data.utils.JDBCUtil.queryList

import scala.collection.mutable.ArrayBuffer
import scala.reflect._

class MysqlProvider extends DataProvider {

  override def init() = Class.forName("com.mysql.cj.jdbc.Driver")

  override def close(): Unit = ???

  override def full[T](database: String, table: String)(implicit m: ClassTag[T]): ArrayBuffer[T] = queryList[T](
    connection = getConnection(database),
    querySql = s"select * from $database.$table",
    clz = m,
    toCamel = true
  )

  private def getConnection(database: String = "test"): Connection = DriverManager.getConnection(
    DatabaseConstant.MysqlConstant.URL(database),
    DatabaseConstant.MysqlConstant.USER_NAME,
    DatabaseConstant.MysqlConstant.USER_PASSWORD
  )

  override def increment[T](odlArr: ArrayBuffer[T], f1: String, f2: String)(implicit m: ClassTag[T]): ArrayBuffer[T] = ???
}

object MysqlProvider {
  def apply(): MysqlProvider = {
    val mysqlProvider = new MysqlProvider()
    mysqlProvider.init()
    mysqlProvider
  }
}
